package com.mipo.iflytek.cycore.zhoushan;

import java.io.File;
import java.util.HashMap;
import java.util.List;

import cn.cycore.epdres.EpdResClient;
import cn.cycore.epdres.models.AuditStatusEnum;
import cn.cycore.epdres.models.CategoryModel;
import cn.cycore.epdres.models.ResourceBasicModel;
import cn.cycore.epdres.models.ResourceModel;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mipo.iflytek.cycore.jinzhou.FileMd5;

/**
 * cycore的资源服
 * 
 * @author kitty
 * @date 2018 4 13
 */
public class EpdResMainTest2Kitty {
	
	private static EpdResClient epdResClient = null;
	
	/**
	 * 获取资源服务sdk客户
	 */
	private static EpdResClient getResourceClient() {
		if (epdResClient == null) {
			//PropertiesConfiguration config = PropertiesConfigurationFactoryBean.getPropertiesConfiguration();
			//String appName = config.getString("usercenter.appname.default");
			//String appSecret = config.getString("usercenter.appsecret.default");
			//String serverUrl = config.getString("epdres.server.Url");
			// superdiamond配置：首页 >> php项目配置 - ledc_app_php - production >> 预览 
			String appName = "4d3d3d741c524a38aab4845280040f43";
			String appSecret = "bde9a1723d3c3158adcc97dde7413403";
			String serverUrl = "http://epdres.zstest.changyan.cn";
			
//			String appName = "rrt_jinzhou";
//			String appSecret = "695ed724b0553de7a711a0e1ffbb82c8";
//			String serverUrl = "http://epdres.cloud.lnjzedu.gov.cn";
			epdResClient = new EpdResClient(appName, appSecret);
			epdResClient.setHost(serverUrl);
		}
		return epdResClient;
	}
	
	/**
	 * 资源文件存放
	 * 资源的元数据信息存在mongodb:172.31.12.20 27017 admin root/jinzhou@2017
	 * @throws Exception 
	 */
	public static void main(String[] args) throws Exception {
		getType();
		
	}
	
	
	public static void booklibrary2(){
		// 查询资源服务获取列表
		HashMap<String, String> mapPhase = new HashMap<String, String>();// 创建map
		List<HashMap<String, String>> list = getResourceClient().getTree().getTreeNodes("booklibrary2", "phase", mapPhase);
		for (HashMap<String, String> li : list) {
			System.out.println(li);
		}
	}
	
	
	public static void res() {
		ResourceModel res=getResourceClient().getResource().getResourceInfo("7d72fa3fc2804d769a188a6e6064baa5");//获取资源信息
		System.out.println(res.getTitle()); // 舟山教学通问题记2.docx
		String[] resources=res.getResources();//获取附属资源列表
		ResourceModel condition = new ResourceModel();
		condition.setTitle("123.docx");
		boolean bool = getResourceClient().getResource().updateResourceInfo("7d72fa3fc2804d769a188a6e6064baa5",condition); //更新资源
		System.out.println(bool); //true
	}
	
	/**
	 * 获取资源类型
	 */
	public static void getType() {
		List<JSONObject> grade = getResourceClient().getCategory().getCategoryValueList("grade");
		System.out.println(JSONArray.toJSON(grade));// [{"code":"01","name":"�?年级"},{"code":"02","name":"二年�?"},{"code":"03","name":"三年�?"},{"code":"04","name":"四年�?"},{"code":"05","name":"五年�?"},{"code":"06","name":"六年�?"},{"code":"07","name":"七年�?"},{"code":"08","name":"八年�?"},{"code":"09","name":"九年�?"},{"code":"10","name":"高一"},{"code":"11","name":"高二"},{"code":"12","name":"高三"},{"code":"19","name":"高中"},{"code":"14","name":"小班"},{"code":"15","name":"中班"},{"code":"16","name":"大班"},{"code":"17","name":"学前综合"},{"code":"18","name":"课外"},{"code":"13","name":"演示"},{"code":"00","name":"其他"},{"code":"20","name":"职教�?"},{"code":"21","name":"职教�?"},{"code":"22","name":"职教�?"}]
		List<JSONObject> type = getResourceClient().getCategory().getCategoryValueList("type");
		System.out.println(JSONArray.toJSON(type));// [{"code":"01","name":"�?年级"},{"code":"02","name":"二年�?"},{"code":"03","name":"三年�?"},{"code":"04","name":"四年�?"},{"code":"05","name":"五年�?"},{"code":"06","name":"六年�?"},{"code":"07","name":"七年�?"},{"code":"08","name":"八年�?"},{"code":"09","name":"九年�?"},{"code":"10","name":"高一"},{"code":"11","name":"高二"},{"code":"12","name":"高三"},{"code":"19","name":"高中"},{"code":"14","name":"小班"},{"code":"15","name":"中班"},{"code":"16","name":"大班"},{"code":"17","name":"学前综合"},{"code":"18","name":"课外"},{"code":"13","name":"演示"},{"code":"00","name":"其他"},{"code":"20","name":"职教�?"},{"code":"21","name":"职教�?"},{"code":"22","name":"职教�?"}]
		
		
	}
	
	
	
}
